<template>
    <el-card>
        <div slot="header">
            <span>文章发表</span>
        </div>
        <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="标题">
                <el-input v-model="form.title"></el-input>
            </el-form-item>
            <el-form-item label="是否置顶">
                <el-radio-group v-model="form.is_sticky">
                    <el-radio :label="1">是</el-radio>
                    <el-radio :label="0">否</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="内容">
                <Edit_Tool v-model="form.content"></Edit_Tool>
            </el-form-item>
            <el-form-item>
                <el-button @click="handleEdit" type="primary">发布文章</el-button>
            </el-form-item>
        </el-form>
    </el-card>
</template>
<script>
import { Notice } from '@/api';
import Edit_Tool from '@/plugins/edit-tool.vue';
export default{
    components:{Edit_Tool},
    data(){
        return{
            form:{
                title:'',
                is_sticky:'',
                content:'',
            }
        }
    },
    created(){
        this.init();
    },
    methods:{
        async init() {
			let notice_id = this.$route.params.notice_id;
			let { status, msg, data } = await Notice.detail({ notice_id });
			if (status) {
				this.form = { ...data };
			} else {
				this.$message.error(msg)
			}
		},
        handleEdit(){
            this.$refs.form.validate(async (valid) => {
				if (valid) {
					let { status, msg, data } = await Notice.edit({ ...this.form });
					if (status) {
						// 信息提示
						this.$message.success(msg);
						this.$router.push('/notice/list')
					} else {
						// 信息提示
						this.$message.error(msg);
					}
				}
			});
        }
    }
}
</script>